package com.itheima.json;

import com.alibaba.fastjson.JSON;

public class FastJsonDemo {
    public static void main(String[] args) {
        //1.将Java对象转换为json对象
        User u = new User();
        u.setId(1);
        u.setUsername("张三");
        u.setPassword("123");

        String jsonString = JSON.toJSONString(u);
        System.out.println(jsonString);
        //2。将JSON字符串转换为Java对象
        User user = JSON.parseObject("{\"id\":1,\"password\":\"123\",\"username\":\"张三\"}", User.class);
        System.out.println(user);

        /*
        控制台输出：
        {"id":1,"password":"123","username":"张三"}
        User{id=1, username='张三', password='123'}
         */
    }
}
